package com.volcreate.inn.utils;

import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author zxc
 * @version 0.0.2
 * @date 2020/8/27
 */

@Component
public class HtmlConvert {


    public static void main(String[] args) {
        String pattern = "@[\u4e00-\u9fa5\\w]+ :";
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher("@_游客1 :   你是大傻逼哈哈哈");
        System.out.println(m.find());
//        System.out.println(m.start());
//        System.out.println(m.end());
        System.out.println(m.group());
        String nickname = m.group().substring(1, m.end() - 2);
        System.out.println(nickname);
        System.out.println(nickname.length());


    }

    public static String textToNickname(String inputStr) {
        return null;
    }


    /**
     * String str = "this is {0} template {1}, {2}";
     * String[] paramAry = new String[]{"a", "text", "right!"};
     * System.out.printf(getFormatText(str, paramAry));
     * <p>
     * this is a template text, right!
     *
     * @param str
     * @param paramAry
     * @return
     */
    private String getFormatText(String str, String[] paramAry) {
        //格式化模版内容
        for (int i = 0; i < paramAry.length; i++) {
            str = str.replaceAll(String.format("\\{%d\\}", i), paramAry[i]);
        }
        return str;
    }

}
